/*
 * @Author: hewenke
 * @Date: 2023-09-13 16:13:14
 * @LastEditors: hewenke hewenke@dataojo.com
 * @LastEditTime: 2023-09-15 15:27:44
 * @FilePath: \react-app\src\pages\login\index.js
 * @Description: Login page
 */
import { useState } from 'react'
import { apiReqs } from '@/api'
import { useNavigate } from 'react-router-dom'
import { Button, Input } from 'antd'
import './styles.less'

function Login() {
  // 创建路由钩子
  const navigate = useNavigate()

  // 组件中自维护的实时数据
  const [account, setAccount] = useState('')
  const [password, setPassword] = useState('')

  // 登录
  const login = () => {
    apiReqs.signIn({
      data: {
        account,
        password,
      },
      success: (res) => {
        console.log(res)
        navigate('/home')
      },
    })
  }

  return (
    <div className="login-wrapping">
      <div className="ipt-con">
        <Input placeholder="账号" value={account} onChange={(e) => { setAccount(e.target.value) }} />
      </div>
      <div className="ipt-con">
        <Input.Password placeholder="密码" value={password} onChange={(e) => { setPassword(e.target.value) }} />
      </div>
      <div className="ipt-con">
        <Button type="primary" block={true} onClick={login}>登录</Button>
      </div>
    </div>
  )
}

export default Login